package hw3.proxy.core;

import java.io.ByteArrayInputStream;
import java.io.IOException;

import org.apache.http.impl.io.AbstractSessionInputBuffer;
import org.apache.http.params.BasicHttpParams;

/**
 * This class represents a string buffer that is used in parsing of HTTP messages.
 * The class extends the functionality of AbstractSessionInputBuffer.
 * 
 * @author Adam Levi
 * @author Marina Skarbovsky
 */
public class StringInputBuffer extends AbstractSessionInputBuffer
{
	/**
	 * Constructor
	 * @param source - the string that backs the buffer.
	 */
	public StringInputBuffer(String source)
	{
		super();
		ByteArrayInputStream byteStream = new ByteArrayInputStream(source.getBytes());
		super.init(byteStream, ConfigurationProperties.SOCKET_BUFFER_SIZE, new BasicHttpParams());
	}
	
	@Override
	public boolean isDataAvailable(int timeout) throws IOException
	{
		return true;
	}
	
	/**
	 * Fills the buffer with characters from the source string
	 */
	public int fillBuffer() throws IOException
	{
		return super.fillBuffer();
	}
}
